package cn.billy.basic.listener;

import cn.billy.basic.service.IPermissionScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
// 表示自定义监听器，需要被spring管理
@WebListener
// 加上次注解就可以在类中打印日志
@Slf4j
public class PermissionScanInitInstener  implements ServletContextListener {

    @Autowired
    private IPermissionScanService iPermissionScanService;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                log.info("contextInitialized.start....");
                iPermissionScanService.scanPermission();
                log.info("contextInitialized.stop....");
            }
        }).start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        log.info("PermissionScanInitInstener stop..");
    }
}
